var e = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/asyncToGenerator"), r = require("../../utils/tool"), t = getApp(), o = require("../../http/userApi.js");

Page({
    data: {},
    onLoad: function(e) {
        this.setData({
            VoiceToggle: !(!1 === wx.getStorageSync("VoiceToggle")),
            BarrageToggle: !(!1 === wx.getStorageSync("BarrageToggle"))
        });
        var a = wx.getAccountInfoSync(), r = a.miniProgram.version;
        "develop" == a.miniProgram.envVersion ? r = "开发版" : "trial" == a.miniProgram.envVersion && (r = "体验版"), 
        this.setData({
            version: r
        });
    },
    voiceToggleOnTap: function(e) {
        this.setData({
            VoiceToggle: !this.data.VoiceToggle
        }), wx.setStorageSync("VoiceToggle", this.data.VoiceToggle);
    },
    barrageToggleOnTap: function(e) {
        this.setData({
            BarrageToggle: !this.data.BarrageToggle
        }), wx.setStorageSync("BarrageToggle", this.data.BarrageToggle);
    },
    appRuleOnTap: function(e) {
        wx.navigateTo({
            url: "/pages/app-rule/app-rule"
        });
    },
    updateOnTap: function() {
        var e = this;
        wx.getUserProfile({
            lang: "zh_CN",
            desc: "用于完善会员资料",
            success: function(a) {
                console.log(a), e.uploadUserInfo(a.userInfo);
            }
        });
    },
    uploadUserInfo: function(n) {
        return a(e.default.mark(function a() {
            var g;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.prev = 0, t.showLoading(), e.next = 4, (0, r.promising)(wx.login)();

                  case 4:
                    return g = e.sent, e.next = 7, o.updateUserInfo(g.code, n);

                  case 7:
                    g = e.sent, t.data.loginInfo.userInfo = g.data, wx.setStorageSync("LoginInfo", t.data.loginInfo), 
                    wx.showToast({
                        title: "更新成功"
                    }), e.next = 17;
                    break;

                  case 13:
                    e.prev = 13, e.t0 = e.catch(0), console.log(e.t0), wx.hideLoading();

                  case 17:
                  case "end":
                    return e.stop();
                }
            }, a, null, [ [ 0, 13 ] ]);
        }))();
    }
});